// ----------------------------------
// RSDK Project: Sonic Essence
// Script Description: SSZ 2 Intro
// Script Author: Tails LP
// ----------------------------------

//-------Aliases-------//
private alias 0 : CUTSCENE_NONE
private alias 1 : CUTSCENE_MIDZONE
private alias 2 : CUTSCENE_ENDZONE


private alias 0 : INTRO_INT
private alias 1 : INTRO_LOADPOS
private alias 2 : INTRO_FADEOUT
private alias 3 : INTRO_LOADTITLECARD
private alias 4 : INTRO_LOADBOUNDS

private alias object.value0 : cutscene.timer

private alias 666 : GROUP_CUTSCENES

//-------Function declarations-------//

//-------Static Values-------//

//-------Tables-------//


//-------Functions-------//



event ObjectMain
	switch object.state
	case INTRO_INT
		
		object.groupID = GROUP_CUTSCENES
		if cutscene.mode == CUTSCENE_MIDZONE
				object.alpha = 500
				foreach (TypeName[Title Card], arrayPos1, ACTIVE_ENTITIES)
					arrayPos1 += 1
					if object[arrayPos1].groupID == GROUP_CUTSCENES
						object[arrayPos1].state ++
						stopMusic()
						foreach	(GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
							if object[currentPlayer].xpos > object.xpos
								object[currentPlayer].direction = FLIP_X
							endif
							object[currentPlayer].up = 1
							object[currentPlayer].controlLock = -1
							object[currentPlayer].state = PlayerObject_LookingUp
							object[currentPlayer].animation = 46
						next
						stage.state = STAGE_RUNNING
					endif
				next
		endif
		break
	case INTRO_LOADPOS
		foreach	(GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			object[currentPlayer].up = 1
			object[currentPlayer].controlLock = -1
			object[currentPlayer].state = PlayerObject_LookingUp
			object[currentPlayer].animation = 46
		next

		callFunction(SSZSetup_LoadPlayerStartPos)
		object[21].Type = 40 //Pause Menu, TypeName does not work since it's in gameconfig
		object[21].priority = PRIORITY_ACTIVE_PAUSED

// Camera and Sighnpost Values not done yet!!!

		object.state ++
		break
		
	case INTRO_FADEOUT
		foreach	(GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			object[currentPlayer].up = 1
			object[currentPlayer].controlLock = -1
			object[currentPlayer].state = PlayerObject_LookingUp
			object[currentPlayer].animation = 46
		next
			
			object.alpha -= 2
			if object.alpha <= 0
				object.state ++
			endif
		break
		
	case INTRO_LOADTITLECARD
		foreach	(GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			object[currentPlayer].up = 1
			object[currentPlayer].controlLock = -1
			object[currentPlayer].state = PlayerObject_LookingUp
			object[currentPlayer].animation = 47
		next

		object.value1++
		if object.value1 >= 80
			foreach	(GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
				object[currentPlayer].up = 1
				object[currentPlayer].controlLock = -1
				object[currentPlayer].state = PlayerObject_LookingUp
				object[currentPlayer].animation = ANI_LOOKINGUP
			next
		end if
		
		if object.value1 >= 120
		
				object[currentPlayer].direction = FLIP_X

		end if

		if object.value1 >= 140
			object[currentPlayer].direction = FLIP_NONE
			cutscene.timer++
		end if


			

		if cutscene.timer >= 60
			object.state ++
				foreach (TypeName[Title Card], arrayPos1, ACTIVE_ENTITIES)
					object[arrayPos1].state ++
				next
			cutscene.timer = 0
		endif
		break
		
	case INTRO_LOADBOUNDS
			foreach	(GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
				object[currentPlayer].up = 0
				object[currentPlayer].down = 0
				object[currentPlayer].left = 0
				object[currentPlayer].right = 0
				object[currentPlayer].jumpPress = 0
				object[currentPlayer].jumpHold = 0
				object[currentPlayer].controlLock = 0
				object[currentPlayer].controlMode = 0
				object[currentPlayer].state = PlayerObject_HandleGround
			next
			foreach (TypeName[Pause Menu], arrayPos0, ALL_ENTITIES)
				object[arrayPos0].state = 0
			next
		cutscene.timer ++
		if cutscene.timer > 240
			cutscene.timer = 0
			

			stage.newXBoundary1 = 0
			temp0 = tileLayer[0].xsize
			temp0 <<= 7
			stage.newXBoundary2 = temp0
			stage.newYBoundary1 = 0
				
			object.type = TypeName[Blank Object]
		endif
		break
	endswitch
	

end event

event ObjectDraw
		drawRect(0, 0, screen.xsize, screen.ysize, 255, 255, 255, object.alpha)
end event

event ObjectStartup
	arrayPos0 = 32
	while arrayPos0 < 0x420
		if object[arrayPos0].type == TypeName[SSZ 2 Intro]
			object[arrayPos0].drawOrder = 6
			object[arrayPos0].priority 	= PRIORITY_ACTIVE
			object[arrayPos0].groupID = GROUP_CUTSCENES
		end if
		arrayPos0++
	loop
end event

event RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endevent
